package com.wpc.smspringmvc.test;

import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import com.wpc.smspringmvc.dao.UserMapper;
import com.wpc.smspringmvc.model.User;


public class UserMapperText {

	@Test
	public void addUserTest() throws Exception {
	
	String resource = "mybatis/mybatis-config.xml";
	InputStream iS = Resources.getResourceAsStream(resource);
	SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(iS);

	SqlSession sqlSession = sqlSessionFactory.openSession();

	UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
	
	User user = new User();
	
	user.setName("李四");
	user.setAge(18);
	user.setSex("男");
	
	int rownum =userMapper.addUser(user);
	System.out.println("影响的行数："+rownum+"行");
	sqlSession.commit();
	
	sqlSession.close();
	
	}
}
